package com.example.aaaapp.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.aaaapp.R;

public class BaseActivity extends AppCompatActivity {

    Context mContext;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base);

        mContext = this;
    }

    public void navigationTo(Class toClass) {
        Intent intent = new Intent(mContext, toClass);
        startActivity(intent);
    }

    public void showMessage(String message) {
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
        Log.e("yeqiang", message);
    }

    public void showMessageAsync(String message) {
        Looper.prepare();
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
        Log.e("yeqiang", message);
        Looper.loop();
    }

    public void saveStringToSp(String key, String value) {
        SharedPreferences sp = this.getSharedPreferences("sp_ttit", MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(key, value);
        editor.commit();
    }
}